<?php
declare (strict_types = 1);

namespace app\stores\middleware;

use app\common\logic\TokenLogic;


class PlatformCheck{

    use \app\BaseTrait;

    /**

     * 处理请求

     *  验证是否登录是否正确的中间件

     * @param \think\Request $request

     * @param \Closure       $next

     * @return Response

     */

    public function handle($request, \Closure $next)

    {

        $token = $request->param('auth_token');

        if(empty($token)){ //需要给MEMBERID重置

            $request->memberId = 0;

        }else{

            $datas = TokenLogic::getMiniMemberId($token);

            if($datas != false){

                $request->memberId = $datas;

            }else{

                $request->memberId = 0;

            }

        }

        return $next($request);

    }

}